<template>
  <p class="g-name">{{goods.name}}</p>
  <p class="g-desc">{{goods.desc}}</p>
  <p class="g-price">
    <span>{{goods.price}}</span>
    <span>{{goods.oldPrice}}</span>
  </p>
  <div class="g-service">
    <dl>
      <dt>促销</dt>
      <dd>12月好物放送，App领券购买直降120元</dd>
    </dl>
    <dl>
      <dt>配送</dt>
      <dd>至 <XtxCity @change="changeCity" :fullLocation="fullLocation"/></dd>
    </dl>
    <dl>
      <dt>服务</dt>
      <dd>
        <span>无忧退货</span>
        <span>快速退款</span>
        <span>免费包邮</span>
        <a href="javascript:;">了解详情</a>
      </dd>
    </dl>
  </div>
</template>

<script>
import {  ref } from 'vue'
export default {
    name:'GoodsName',
     props:{
        goods:{
            type:Object,
            default:()=>{}
        }
    },
    setup(props){
        // 提供给后台的四项数据 (没登录)
        const provinceCode = ref('110000')
        const cityCode = ref('119900')
        const countyCode = ref('110101')
        const fullLocation = ref('北京市 市辖区 东城区')
        // 取出用户收货地址中默认的地址给四个数据赋值 (已登录)
        if(props.goods.userAddresses){
            const defaulAddress = props.goods.userAddresses.find(item=>item.isDefualt === 1)
            if(defaulAddress){
                provinceCode.value=defaulAddress.provinceCode
                cityCode.value=defaulAddress.cityCode
                countyCode.value=defaulAddress.countyCode
                fullLocation.value=defaulAddress.fullLocation
            }
        }
        const changeCity=(result)=>{
            provinceCode.value = result.provinceCode
            cityCode.value = result.cityCode
            countyCode.value = result.countyCode
            fullLocation.value = result.fullLocation
        }
        return {fullLocation,changeCity}
    }
}
</script>

<style lang='less' scoped>
@import '~@/assets/styles/variables.less';
.g-name{
    color: #333;
    font-size: 22px;
}
.g-desc{
    color: #999;
    margin-top: 20px;
}
.g-price{
    margin-top: 20px;
    span{
        &:first-child{
            color: @priceColor;
            font-size: 22px;
            margin-right: 3px;
        }
        &:last-child{
            color: #999;
            font-size: 16px;
            text-decoration: line-through;
        }
    }
}
.g-service{
    background-color: #f5f5f5;
    width: 500px;
    padding: 20px 20px 0 10px;
    margin-top: 10px;
    dl{
        display: flex;
        padding-bottom: 20px;
        align-items: center;
        dt{
            width: 50px;
            color: #999;
        }
        &:last-child{
            dd{
               span{
                    color: #666;
                    &::before{
                    content: "•";
                    color: @xtxColor;
                    margin-right: 4px;
                    }
               }
               a{
                    color: @xtxColor;
                    margin-left: 8px;
               }
            }
        }
    }
}
</style>